Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
custom-event
Advanced tools
The custom-event npm package allows developers to create and manage custom events in JavaScript environments. This package is particularly useful for handling custom event-driven interactions in applications, making it easier to manage asynchronous code and event-based logic.
Creating custom events
This feature allows developers to create a new custom event with a specified type and optional details. The event can then be dispatched to trigger event listeners that are set up to respond to it.
const CustomEvent = require('custom-event');
const event = new CustomEvent('my-event', { detail: { message: 'Hello world!' } });
document.dispatchEvent(event);
Listening to custom events
This code sets up an event listener for 'my-event'. When this event is dispatched, the listener triggers and logs the message contained in the event's details.
document.addEventListener('my-event', function(e) { console.log(e.detail.message); });
EventEmitter3 is a high-performance event emitter. It provides similar functionalities to custom-event but with a focus on performance and additional features like wildcard listeners. Compared to custom-event, EventEmitter3 offers a broader API for managing events in more complex scenarios.
Wolfy87's EventEmitter is another alternative that offers a similar event management system. It supports features like namespaced events, which can help in organizing event types and listeners more efficiently. It is more feature-rich compared to custom-event, providing more flexibility in handling events.
CustomEvent
constructorhttps://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent
$ npm install custom-event
var CustomEvent = require('custom-event');
// add an appropriate event listener
target.addEventListener('cat', function(e) { process(e.detail) });
// create and dispatch the event
var event = new CustomEvent('cat', {
detail: {
hazcheeseburger: true
}
});
target.dispatchEvent(event);
FAQs
Cross-browser `CustomEvent` constructor
The npm package custom-event receives a total of 1,945,539 weekly downloads. As such, custom-event popularity was classified as popular.
We found that custom-event demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.